package cn.gs.web;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.gs.domain.Customer;
import cn.gs.domain.LinkMan;
import cn.gs.domain.Visit;
import cn.gs.service.VisitService;
import cn.gs.utils.StrUtil;

@Component(value = "visitAction")
@Scope(value = "prototype")

public class VisitAction extends ActionSupport implements ModelDriven<Visit> {

	Visit visit = new Visit();
	@Resource(name = "VisitService")
	VisitService vs;
	List<Customer> list;
	private Customer customer;
	private String pageCount; //总记录条数
	private String page;  //翻页时当前第几页
	private String pCount; //总共多少页

	public String selCustomer() {
		list = vs.selectCustom();
		ActionContext.getContext().put("list", list);
		Customer c = list.get(0);
		return "selCustomSuc";
	}

	public String add() {
		visit.setVisit_id(StrUtil.getUUID32());
		vs.add(visit);
		return "addSuc";
	}

	public String paging() {
		if (page == null) {
			page = "1";
		}
		int i = Integer.valueOf(page);
		List<Visit>  list1 = vs.paging(i);
		
		System.out.println("action读出来的lsit"+list1);
		ActionContext.getContext().put("list", list1);
		List l = vs.selectPageCount();
		pageCount = String.valueOf(l.get(0));
		int a = Integer.valueOf(pageCount);
		int b = 0;
		if (a % 3 == 0) {
			b = a / 3;
		} else {
			b = a / 3 + 1;
		}
		pCount = String.valueOf(b);
		ActionContext.getContext().put("pCount", pCount);
		ActionContext.getContext().put("pageCount", pageCount);
		return "pagSuc";
	}
	
	public String selectById() {
		visit= vs.selectByID(visit.getVisit_id());
		List<Customer> list = vs.selectCustom();
		ActionContext.getContext().put("visit", visit);
		ActionContext.getContext().put("list", list);
		return "selIdSuc";
	}
	
	public String delete() {
		vs.delete(visit.getVisit_id());
		return "delSuc";
	}
	
	public String update() {
		vs.update(visit);
		return "updSuc";
	}
	
	
	public String selName() {
	try {
			List<Visit> list1= vs.selName(visit.getVisit_interviewee());
			System.out.println("外层"+list);
			ActionContext.getContext().put("list", list1);
			return "selnamesuc";
		} catch (Exception e) {
			return "selnamedef";
		}		
	}

	public Visit getModel() {
		return visit;
	}

	public List<Customer> getList() {
		return list;
	}

	public void setList(List<Customer> list) {
		this.list = list;
	}

	public String getPageCount() {
		return pageCount;
	}

	public void setPageCount(String pageCount) {
		this.pageCount = pageCount;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public String getpCount() {
		return pCount;
	}

	public void setpCount(String pCount) {
		this.pCount = pCount;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	
	
}
